package gui;

import java.io.IOException;

import parsing.InvalidSyntaxException;

import gui.MainWindow;
import world.*;

public class Initializer {

	/**
	 * Constructs a CritterWorld and a MainWindow to display it.
	 * Requires: a file "constants.txt" in the local directory
	 * containing the appropriate constants
	 */
	public static void main(String[] args) {
		CritterWorld world = null;
		if(args.length == 0){
			try {
				world = new CritterWorld("constants.txt");
			} catch (IOException e) {
				System.out.println(e.getMessage());
			}
		}
		else if (args.length == 1){
			try {
				LoadState state = new LoadState();
				world = new CritterWorld("constants.txt", args[0], state);
				if(!state.successful())
					System.out.println("The world was sucessfully loaded but not every component was added" +
									 "\nbecause one or more was in an illegal location.");
			} catch (InvalidSyntaxException e) {
				System.out.println(e.getMessage());
			} catch (IllegalArgumentException e) {
				System.out.println(e.getMessage());
			} catch (IOException e) {
				System.out.println(e.getMessage());
			}
		} else{
			System.out.println("Requires either no parameters or just one parameter containing a world file name.");
			System.exit(0);
		}
		MainWindow view = new MainWindow(world);
	}

}
